<template>
  <div class="w">
    <header>
      <h6>
        <div class="logo">
          <a href=""><img src="../../assets/logo.png" alt="" /></a>
        </div>
      </h6>
    </header>
    <main>
      <router-link to="">
        <div class="bg"></div>
      </router-link>
      <div class="form">
        <div class="form_header">
          <span>短信登录</span>
          |
          <span>账号密码</span>
        </div>
        <div class="form_body">
          <el-form label-width="0" :model="formLabelAlign">
            <el-form-item>
              <el-input
                v-model="formLabelAlign.phone"
                placeholder="手机号码"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="formLabelAlign.pass"
                placeholder="用户密码"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="formLabelAlign.code"
                placeholder="请输入图形验证码"
              ></el-input>
              <div class="code" v-html="codePic" @click="getCode"></div>
            </el-form-item>
            <button class="btn" @click="upLogin">立即登录</button>
            <router-link to="/register">
              <span class="register">免费注册</span></router-link
            >
          </el-form>
        </div>
        <div class="form_footer">
          <img src="../../assets/subLogo.png" alt="" />
        </div>
      </div>
    </main>
    <footer>
      <p>
        万表网名表商城 版权所有 2008-2017 ICP备案证书号:粤ICP备09108738号
        网监备案:4401060103141
      </p>
      <p>广州市万表科技股份有限公司 地址:广州市番禺区番禺大道北60-1号</p>
      <p>Copyright 2008-2017 WWW.WBIAO.CN.LTD ALL RIGHT RESERVED.</p>
    </footer>
  </div>
</template>

<script>
import { getPicCode } from "@/services/code.js";
import { login } from "@/services/login.js";
import { logout } from "@/services/logout.js";

export default {
  data() {
    return {
      formLabelAlign: {
        phone: "",
        pass: "",
        code: "",
      },
      codePic: "",
    };
  },
  methods: {
    open() {
      this.$message({
        message: "恭喜您登录成功，2s后跳转",
        type: "success",
        duration: 2000,
      });
    },
    // 图片验证码请求
    async getCode() {
      const res = await getPicCode({});
      this.codePic = res.data.data;
    },
    // 登录请求
    async upLogin() {
      const res = await login({
        phone: this.formLabelAlign.phone,
        password: this.formLabelAlign.pass,
      });
      if (res.status == 200) {
        this.open();
        setTimeout(() => {
          this.$router.push("/");
        }, 2000);
        console.log(res.data.result.token);
      }else {
        alert("手机号或者密码不正确")
      }
    },

    async out() {
      const res = await logout({});
      console.log(res);
    },
  },

  created() {
    this.getCode();
  },
};
</script>

<style scoped lang="scss">
* {
  margin: 0;
  padding: 0;
}
.w {
  width: 100%;
  h6 {
    width: 1000px;
    height: 100px;
    margin: 25px auto 0;

    .logo {
      width: 121px;
      height: 75px;
      vertical-align: middle;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  main {
    position: relative;
    width: 100%;
    height: 580px;
    .bg {
      width: 100%;
      height: 100%;
      background-image: url("./logo_bg.png");
    }
    .form {
      position: absolute;
      top: 50px;
      left: 900px;
      width: 380px;
      height: 460px;
      background-color: #fff;
      .form_header {
        width: 269px;
        height: 26px;
        margin: 0 55px;
        padding: 40px 0 20px;
        font-size: 20px;
        color: grey;
        span {
          display: inline-block;
          width: 126px;
          height: 26px;
          line-height: 26px;
          text-align: center;
        }
      }
      .form_body {
        width: 300px;
        height: 265px;
        margin: 0 auto;
        .el-form {
          .el-form-item {
            margin-top: 15px;
            .el-input {
              display: inline-block;
              width: 300px;
              height: 44px;
            }
            &:nth-child(3) {
              .el-input {
                width: 200px;
                margin-right: 5px;
              }
            }
            .code,
            .sms {
              display: inline-block;
              width: 94px;
              height: 44px;
              color: #fff;
              vertical-align: middle;
              background-color: #b1b1b1;
              border: none;
              cursor: pointer;
            }
          }
          .btn {
            width: 300px;
            height: 44px;
            margin: 12px 0;
            font-size: 18px;
            color: white;
            border: none;
            background-color: #cc5252;
            cursor: pointer;
          }
        }
      }
      .form_footer {
        display: flex;
        justify-content: end;
        margin-top: 10px;
      }
    }
  }
  footer {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    //   width: 640px;
    height: 61px;
    padding: 50px 0;
    font-size: 12px;
    color: #999;
  }
}
</style>
